<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>毕业设计项目</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<script type="text/javascript" src="../../js/jquery-2.2.3.js"></script>
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<script src="../../script/common.js"></script>
</head>
<body>

<div class="page_title">客户信息管理 > 客户信息</div>
<div class="button_bar">
	<button class="common_button" onclick="help('');">帮助</button>
	<button class="common_button" onclick="to('linkman.html');">联系人</button>
	<button class="common_button" onclick="to('activities.html');">交往记录</button>
	<button class="common_button" onclick="to('orders.html');">历史订单</button>
	
	<button class="common_button" onclick="back();">返回</button>
	<button class="common_button" onclick="saveCustomer();">保存</button>
</div>
<table class="query_form_table">
	<tr>
		<th>客户编号</th>
		<td id="showCstNo"></td>
		<th>名称</th>
		<td><input id="showCstName" value="" /><span class="red_star">*</span></td>
	</tr>
	<tr>
		<th>地区</th>
		<td>
			<select id="region">
			</select>
			<span class="red_star">*</span></td>
		<th>客户经理</th>
		<td>
			<select id="manage">
			</select><span class="red_star">*</span>
		</td>
	</tr>	
	<tr>
		<th>客户等级</th>
		<td>
			<select id="levelLabel">
			</select><span class="red_star">*</span>
		</td>
		<th>　</th>
		<td>　</td>
	</tr>
	<tr>
		<th>客户满意度</th>
		<td>
			<select id="satisfy">
			</select><span class="red_star">*</span>
		</td>
		<th>客户信用度</th>
		<td>
			<select id="credit">
			</select><span class="red_star">*</span>
		</td>
	</tr>
</table>
<br />
<table class="query_form_table" id="table1">
	<tr>
		<th>地址</th>
		<td><input id="showCustAddr" value=""  /><span class="red_star">*</span>
		</td>
		<th>邮政编码</th>
		<td><input id="showCustZip" value=""  size="20" /><span class="red_star">*</span></td>
	</tr>
	<tr>
		<th>电话</th>
		<td>
			<input id="showCustTel" value="" name="T4" size="20"  /><span class="red_star">*</span></td>
		<th>传真</th>
		<td>
			<input id="showCustFax" value="" name="T5" size="20"  /><span class="red_star">*</span>
		</td>
	</tr>	
	<tr>
		<th>网址</th>
		<td>
			<input id="showCustWebsite" value="" name="T6" size="20"  /><span class="red_star">*</span>
		</td>
		<th>　</th>
		<td>　</td>
	</tr>
</table>
<br />
<table class="query_form_table" id="table2">
	<tr>
		<th>营业执照注册号</th>
		<td><input id="showCustLicenceNo" value="" name="T13" size="20" /></td>
		<th>法人</th>
		<td><input id="showCustChieftain" value="" name="T3" size="20" /><span class="red_star">*</span>
		</td>
	</tr>
	<tr>
		<th>注册资金（万元）</th>
		<td>
			<input id="showCustBankroll" value="" name="T7" size="20" /> </td>
		<th>年营业额</th>
		<td>
			<input id="showCustTurnover" value="" name="T8" size="20" />
		</td>
	</tr>	
	<tr>
		<th>开户银行</th>
		<td>
			<input id="showCustBank" value="北京银行 中关村支行" name="T9" size="20" /><span class="red_star">*</span>
		</td>
		<th>银行帐号</th>
		<td><input id="showCustBankAccount" value="62258827238382838" name="T10" size="20" /><span class="red_star">*</span></td>
	</tr>
	<tr>
		<th>地税登记号</th>
		<td>
			<input id="showCustLocalTaxNo" value="" name="T11" size="20" /></td>
		<th>国税登记号</th>
		<td><input id="showCustNationalTaxNo" value="" name="T12" size="20" /></td>
	</tr>
</table>
<p>　</p>
</body>
</html>
<script type="text/javascript">
	$(function () {
		UrlSearch();
    })
    function UrlSearch(){
        var str=location.href; //取得整个地址栏
        var num=str.indexOf("=")//49
        str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]
		return str;
    }


    <!-- 选择下拉框显示所有不重复地区 -->
    $(function(){
        $.get("/CstSustomer/selectSingleCustRegion",function (strRegion) {
            var region = $("#region");
            $.each(strRegion,function (i, item) {
                region.append('<option value=' + item + '>' + item + '</option>');
            })
        },"json");
        showManager();
    });

    <!-- 选择下拉框显示所有不重复的经理 -->
    function showManager(){
        $.get("/CstSustomer/selectSingleCustManageName",function (strManage) {
            var manage = $("#manage");
            $.each(strManage,function (i, item) {
                manage.append('<option value=' + item + '>' + item + '</option>');
            })
        },"json");
        showLevelLabel()
    }

    <!-- 选择下拉框显示所有不重复客户等级 -->
    function showLevelLabel(){
        $.get("/CstSustomer/selectSingleCustLevel",function (strLevel) {
            var level = $("#levelLabel");
            $.each(strLevel,function (i, item) {
                level.append('<option  value=' + item + '>' + item+ '</option>');
            })
        },"json");
        showCstSatisfy();
    }

    <!-- 选择下拉框显示所有不重复的客户满意度 -->
    function showCstSatisfy(){
        $.get("/CstSustomer/selectSingleCustSatisfy",function (strSatisfy) {
            var satisfy = $("#satisfy");
            $.each(strSatisfy,function (i, item) {
                satisfy.append('<option value=' + item + '>' + item + '</option>');
            })
        },"json");
        showCstCredit();
    }

    <!-- 选择下拉框显示所有不重复的客户信誉度 -->
    function showCstCredit(){
        $.get("/CstSustomer/selectSingleCustCredit",function (strCredit) {
            var credit = $("#credit");
            $.each(strCredit,function (i, item) {
                credit.append('<option value=' + item + '>' + item + '</option>');
            })
        },"json");
        showCustomer();
    }

    function showCustomer() {
        var cstNo=UrlSearch();
        $("#showAll").html("");
        $.ajax({
            url:"/CstSustomer/selectByCustNo",
            data:{
                custNo:cstNo
            },
            dataType:'json',
            contentType:"application/json;charset=utf-8",
            success:function (byCustNo) {
                $.each(byCustNo,function (i,customer) {
                    console.log(customer);
                    $("#showCstNo").html("");
                    $("#showCstNo").append(customer.custNo);
                    $("#showCstName").val(customer.custName);
                    $("#showCustAddr").val(customer.custAddr);
                    $("#showCustZip").val(customer.custZip);
                    $("#showCustTel").val(customer.custTel);
                    $("#showCustFax").val(customer.custFax);
                    $("#showCustWebsite").val(customer.custWebsite);
                    $("#showCustLicenceNo").val(customer.custLicenceNo);
                    $("#showCustChieftain").val(customer.custChieftain);
                    $("#showCustBankroll").val(customer.custBankroll);
                    $("#showCustTurnover").val(customer.custTurnover);
                    $("#showCustBank").val(customer.custBank);
                    $("#showCustBankAccount").val(customer.custBankAccount);
                    $("#showCustLocalTaxNo").val(customer.custLocalTaxNo);
                    $("#showCustNationalTaxNo").val(customer.custNationalTaxNo);
                    $("#levelLabel").val(customer.custLevelLabel);
                    $("#manage").val(customer.custManagerName);
                    $("#region").val(customer.custRegion);
                    $("#satisfy").val(customer.custSatisfy);
                    $("#credit").val(customer.custCredit);
                })
            }
        })
    }

    <!-- 通过页面查询条件显示客户信息 -->
    function saveCustomer() {
        var cstNo=UrlSearch();
        var cstName=$.trim($("#showCstName").val());
        var optionRegion=$.trim($("#region option:selected").text());
		var optionManager=$.trim($("#manage option:selected").text());
        var optionLevel=$.trim($("#levelLabel option:selected").text());
        var optionSatisfy=$.trim($("#satisfy option:selected").text());
        var optionCredit=$.trim($("#credit option:selected").text());
        var cstAddr=$.trim($("#showCustAddr").val());
        var cstZip=$.trim($("#showCustZip").val());
        var cstTel=$.trim($("#showCustTel").val());
        var cstFax=$.trim($("#showCustFax").val());
        var cstWebsite=$.trim($("#showCustWebsite").val());
        var cstLicenceNo=$.trim($("#showCustLicenceNo").val());
        var cstChieftain=$.trim($("#showCustChieftain").val());
        var cstBankroll=$.trim($("#showCustBankroll").val());
        var cstTurnover=$.trim($("#showCustTurnover").val());
        var cstBank=$.trim($("#showCustBank").val());
        var cstBankAccount=$.trim($("#showCustBankAccount").val());
        var cstLocalTaxNo=$.trim($("#showCustLocalTaxNo").val());
        var cstNationalTaxNo=$.trim($("#showCustNationalTaxNo").val());

        $.ajax({
            url:"/CstSustomer/updateCustomer",
            data:{
                custNo:cstNo,
                custName:cstName,
                custRegion:optionRegion,
                custManagerName:optionManager,
                custLevelLabel:optionLevel,
                custSatisfy:optionSatisfy,
                custCredit:optionCredit,
                custAddr:cstAddr,
                custZip:cstZip,
                custTel:cstTel,
                custFax:cstFax,
                custWebsite:cstWebsite,
                custLicenceNo:cstLicenceNo,
                custChieftain:cstChieftain,
                custBankroll:cstBankroll,
                custTurnover:cstTurnover,
                custBank:cstBank,
                custBankAccount:cstBankAccount,
                custLocalTaxNo:cstLocalTaxNo,
                custNationalTaxNo:cstNationalTaxNo
            },
            dataType:'json',
            contentType:"application/json;charset=utf-8",
            success:function (i) {
                if(i>0) {
                    alert("修改数据成功!!");
                    window.location.href="list.jsp";
                }
            }
        })
    }
</script>